#pragma once
#ifndef __VANIMATION_H__
#define __VANIMATION_H__

#include "VObject.h"

class VAnimationController;
typedef VSmartPtr<VAnimationController> VAnimationControllerPtr;

class VCoreApi VAnimationable : public VObject
{
public:
	inline VAnimationable(){}
	virtual ~VAnimationable();

	virtual BOOL SupportAnimationController(const VAnimationController* Controller) const { return TRUE;}
	//void PrependController(NiTimeController* pkControl);
	void AddAnimationController(VAnimationController* AnimController);
	inline VAnimationController* GetAnimationControllers() const { return m_AnimationControllers; }
	void RemoveAnimationController(VAnimationController* AnimController);
	void RemoveAllAnimationControllers();
protected:
	void UpdateAnimationControllers(float DeltaTime);

	virtual void OnControllerActived(VAnimationController* AnimationController) {}
	virtual void OnControllerDeactived(VAnimationController* AnimationController){}
protected:
	VAnimationControllerPtr m_AnimationControllers;
};


class VCoreApi VAnimationController : public VObject
{
	friend class VAnimationable;
public:
	inline VAnimationController():m_Active(0)
	{

	}
	virtual ~VAnimationController() {}


	virtual BOOL SupportTarget(const VAnimationable*) const = 0;
	inline void SetActive(BOOL Active) { m_Active = Active; }
	inline BOOL IsActive() const { return m_Active; }
	inline VAnimationable* GetTarget() const { return m_Target; }
	inline VAnimationController* NextController() const { return m_NextController; }

	virtual void Start() = 0;
	virtual void Stop() = 0;
	virtual void Update(float DeltaTime) =0;
	inline void AddRef() { m_RefCnt++; }
	inline void Release() 
	{
		VASSERT(m_RefCnt > 0);
		if (--m_RefCnt == 0)
		{
			VDelete this;
		}
	}
	
protected:
	VAnimationable* m_Target;
	VAnimationControllerPtr m_NextController;
	UINT m_Active:1;
private:
	UINT m_RefCnt;
};


class VAnimation
{
public:
	VAnimation(void);
	~VAnimation(void);
};


#endif 

